package c.e.a.a.f.p.i;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import java.util.Arrays;
import java.util.List;

/* compiled from: SchemaManager */
public final class z extends SQLiteOpenHelper {
    public static final List<a> c;
    public final int a;
    public boolean b = false;

    /* compiled from: SchemaManager */
    public interface a {
        void a(SQLiteDatabase sQLiteDatabase);
    }

    static {
        v vVar = v.a;
        w wVar = w.a;
        x xVar = x.a;
        y yVar = y.a;
        c = Arrays.asList(new a[]{vVar, wVar, xVar, yVar});
    }

    public z(Context context, String str, int i) {
        super(context, str, null, i);
        this.a = i;
    }

    public final void a(SQLiteDatabase sQLiteDatabase, int i, int i2) {
        List list = c;
        if (i2 <= list.size()) {
            while (i < i2) {
                ((a) c.get(i)).a(sQLiteDatabase);
                i++;
            }
            return;
        }
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("Migration from ");
        stringBuilder.append(i);
        stringBuilder.append(" to ");
        stringBuilder.append(i2);
        stringBuilder.append(" was requested, but cannot be performed. Only ");
        stringBuilder.append(list.size());
        stringBuilder.append(" migrations are provided");
        throw new IllegalArgumentException(stringBuilder.toString());
    }

    public void onConfigure(SQLiteDatabase sQLiteDatabase) {
        this.b = true;
        sQLiteDatabase.rawQuery("PRAGMA busy_timeout=0;", new String[0]).close();
        sQLiteDatabase.setForeignKeyConstraintsEnabled(true);
    }

    public void onCreate(SQLiteDatabase sQLiteDatabase) {
        int i = this.a;
        if (!this.b) {
            onConfigure(sQLiteDatabase);
        }
        a(sQLiteDatabase, 0, i);
    }

    public void onDowngrade(SQLiteDatabase sQLiteDatabase, int i, int i2) {
        sQLiteDatabase.execSQL("DROP TABLE events");
        sQLiteDatabase.execSQL("DROP TABLE event_metadata");
        sQLiteDatabase.execSQL("DROP TABLE transport_contexts");
        sQLiteDatabase.execSQL("DROP TABLE IF EXISTS event_payloads");
        if (!this.b) {
            onConfigure(sQLiteDatabase);
        }
        a(sQLiteDatabase, 0, i2);
    }

    public void onOpen(SQLiteDatabase sQLiteDatabase) {
        if (!this.b) {
            onConfigure(sQLiteDatabase);
        }
    }

    public void onUpgrade(SQLiteDatabase sQLiteDatabase, int i, int i2) {
        if (!this.b) {
            onConfigure(sQLiteDatabase);
        }
        a(sQLiteDatabase, i, i2);
    }
}
